#include "findsuccessdlg.h"
#include <QDir>
#include <QPixmap>
#include <QRandomGenerator>
#include "applyfriend.h"
#include "global.h"
#include "ui_findsuccessdlg.h"
#include "usermgr.h"
#include <memory>
FindSuccessDlg::FindSuccessDlg(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::FindSuccessDlg)
    , _si(nullptr)
    , _parent(parent)
{
    ui->setupUi(this);
    setModal(true);
    // 添加标题
    setWindowTitle("添加好友");
}

FindSuccessDlg::~FindSuccessDlg()
{
    delete ui;
}

void FindSuccessDlg::setSearchInfo(std::shared_ptr<SearchInfo> si)
{
    if (si->_icon.isEmpty()) {
        si->_icon = GetRandomIcon();
    }
    QPixmap p(si->_icon);
    p = p.scaled(ui->head_lb->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->name_lb->setText(si->_name);
    _si = si;
    ui->head_lb->setPixmap(p);
}

void FindSuccessDlg::on_add_friend_clicked()
{
    int self_uid = UserMgr::GetInstance()->GetUid();
    if (_si->_uid == self_uid)
        return;
    ApplyFriend *a = new ApplyFriend(this);
    a->setSearchInfo(_si);
    a->show();
}
